package net.osweb.core.tools.utils.date;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
/**
 * 得到开始和结束日期之间每天的日期
 * @author Administrator
 *
 */
public class ExamDateUtil {
	public static List<Date> countDays(Date startDate, Date endDate) {
		List<Date> dayList = new ArrayList<Date>();
		long startValue = startDate.getTime();
		
		long endValue = endDate.getTime();
		
		if (startValue > endValue) {
			long temp = endValue;
			endValue = startValue;
			startValue = temp;
		}
		
		// 计算天数差
		long result = (endValue - startValue) / 1000 / 60 / 60 / 24;
		
		Calendar cal = Calendar.getInstance();
	
		cal.setTime(startDate);
		
		cal.add(Calendar.DATE, 0);
		dayList.add(cal.getTime());
		
		// 计算期间的每一天
		for (int index = 0; index < result; index++) {
			cal.add(Calendar.DATE, 1);
			dayList.add(cal.getTime());
		}
		
		return dayList;
	}
	
	public static String formatCalendar(Calendar c){
		int year = c.get(Calendar.YEAR);
		int month = c.get(Calendar.MONTH) + 1;
		int date = c.get(Calendar.DAY_OF_MONTH);
		String year_str = year+"";
		String month_str = month + "";
		String date_str = date + "";
		if(month<=9){
			month_str = "0" + month;
		}
		if(date<=9){
			date_str = "0" + date;
		}
		String res = year_str + "-" + month_str + "-" + date_str;
		return res;
	}

}





